﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ledict.ConditionExtract.Common
{
   public class WhereLike
    {


       public static string ToWherelike(string Text, string SqlWord,int ISYes)
       {
            string AllStr = "1=1";
            string[] SituArr = Text.Trim().Split(',', '，', '|', ' ', ' ');
            if (ISYes == 1)
            {
                foreach (string str in SituArr)
                {
                    if (str.Trim() != "")
                    {
                        AllStr +=" and " +SqlWord + " like'%" + str + "%'  ";
                    }
                }
            }
            else
            {
                foreach (string str in SituArr)
                {
                    if (str.Trim() != "")
                    {
                        AllStr += " and " + SqlWord + " not like'%" + str + "%'  ";
                    }
                }
            }
            if (AllStr != "")
            {
                AllStr = " and (" + AllStr + " )";
            }
            return AllStr;

            #region 原来代码
            //string AllStr = "";
            //string[] SituArr = Text.Trim().Split(',', '，', '|', ' ', ' ');
            //if (ISYes == 1)
            //{
            //    AllStr += "1=0 ";
            //    foreach (string str in SituArr)
            //    {
            //        if (str.Trim() != "")
            //        {
            //            AllStr += " or " + SqlWord + " like'%" + str + "%'  ";
            //        }
            //    }
            //}
            //else {
            //    AllStr += "1=1 ";
            //    foreach (string str in SituArr)
            //    {
            //        if (str.Trim() != "")
            //        {
            //            AllStr += " and " + SqlWord + " not like'%" + str + "%'  ";
            //        }
            //    }
            //}
            //if (AllStr != "")
            //{
            //    AllStr = " and (" + AllStr + " )";
            //}
            //return AllStr; 
            #endregion
        }
  
    }
}
